package com.klangner.move.behavior
{
  import com.klangner.geom.Vector2D;
  
  public class ArriveBehavior implements IBehavior
  {
    private var _target:Vector2D;
    private var _range:Number;
    
    /**
    * Constructor
    * @param point arrive position
    * @param arriveRange - distance at start decelerate
    */
    public function ArriveBehavior(point:Vector2D, arriveRange:Number){
      _target = point;
      _range = arriveRange;
    }
    
    public function updateForce(obj:ISteeredObject):void{
      var distanceVector:Vector2D = Vector2D.subtract(_target, obj.position);
      var velocity:Vector2D = distanceVector.clone();
      
      velocity.normalize();
      if(distanceVector.length < _range){
        velocity.multiply(distanceVector.length/_range);
      }

      obj.setDesiredVelocity(velocity);
    }

  }
}